<?php
use think\facade\Db;
use Workerman\Worker;
use Workerman\Lib\Timer;
use addons\TfFutures\common\models\Order;
use addons\TfFutures\common\models\Symbol;
use addons\TfFutures\common\models\Member;
use addons\TfFutures\common\models\MemberLever;

$worker        = new Worker();
$worker->name  = 'OverfeeWorker';
$worker->count = 1;
$worker->onWorkerStart = function()
{
    Timer::add(1, function()
    {
    	//合约到期
        $levels = Db::query("SELECT * FROM `rf_addon_tf_futures_member_lever` WHERE `state`='正常'");
		$date = strtotime(date("Y-m-d"));
		foreach ($levels as $k => $v){
		    $edate = strtotime($v['edate']);
		    if($edate<$date){
		        Db::execute("UPDATE `rf_addon_tf_futures_member_lever` SET `state`='过期' WHERE `id`={$v['id']}");
		    }
		}
		
		
		// //过夜费overtime
  //      $symbols = Symbol::find()->where(['status'=>'1','on_sale'=>'on'])->all();
  //      foreach( $symbols as $symbol =>$v ){
	 //       $orders = Order::find()->where(['symbol'=>$v['code'],'state'=>'持仓','status'=>'1'])->all();
	 //       foreach( $orders as $order =>$val ){
	        
	 //           if( strtotime(date("Y-m-d").' '.$v['overtime']) <= time()&& strtotime(date('Y-m-d'))>=strtotime($val['overtime'])){
		// 			$order = Order::find()->where(['id'=>$val->id])->one();
		// 			$member_price= Member::find()->where(['member_id'=>$val->member_id])->one();
	 //               $data = date('Y-m-d H:i:s');
	 //               $order->overfee = $order->overfee+($order['deposit']*$v->overfee/10000);
	 //               $order->overtime = $data;
	 //               $order->save();
	 //           }
	 //       }
            
  //      }
	    
    });
};



// 如果不是在根目录启动，则运行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

